<?php
class Portal_RegisterController extends Mediad2_Controller_Action
{	
	
	public function init() {
		parent::init();
	}
	
	public function indexAction(){
		var_dump(123);
		return;
		$this->helper->setPageView($this->pageview, WEB_TITLE, "register", null);
	}
	
	public function registerAction(){
		//TODO:需要验证邮箱名称长度合理性,不能以1@1.1作为邮箱
		$nickname = $this->httpdata['n'];
		$email = $this->httpdata['e'];
		$pwd = $this->httpdata['p'];
		$this->result = $this->returnResult(0,"miss param");
		if($pwd && $email){
			$user = new Mediad2_Service_Admin_User();
			$where = sprintf("email = '%s'",$email);
			$result = $user->findBy($where);
			if($result->getCode()){
				$d = $result->getData();
				$uid = $d->getUid();
				if(!isset($uid)){
					$model = new Mediad2_Model_User();
					$model->setAddtime(time());
					$model->setEmail($email);
					$model->setPwd(md5($pwd));
					if(!$nickname)$nickname = "";
					$model->setNickname($nickname);
					$model->setIsadmin(0);
					$model->setStatus(1);
					$this->result = $user->insert($model);
				}else{
					$this->result = $this->returnResult(2,"email used");
				}
			}else{
				$this->result = $this->returnResult(0,"db error");
			}
		}
		echo $this->encodeResult($this->result);
	}
}